home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10426 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Novice programmer needs help!
  5. Date: Sun, 17 Mar 96 17:36:34 GMT
  6. Organization: none
  7. Message-ID: <827084194snz@genesis.demon.co.uk>
  8. References: <4ieov7$r5@lantana.singnet.com.sg> <314AB830.684@uthscsa.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <314AB830.684@uthscsa.edu> Monzon@uthscsa.edu "Merardo Monzon" writes:
  15.  
  16. >Novice Porgrammer, I compiled the application you've provided after 
  17. >fixing about 5-7 errors. I don't know what compiler you are using my 
  18. >Mac Symantec C++ compiler compiled the program after I fixed the 
  19. >following errors:
  20.  
  21. The original poster said he was learning C and posted to comp.lang.c so why
  22. on earth are you trying to validate his code with a C++ compiler?
  23.  
  24. >        
  25. >                1) #define totnum 20       //total no. of entries in list=20
  26. >
  27. >                                                                               
  28. >                  //total no. of entries in list=20
  29. >                   Fixed: #define totnum 20
  30. >
  31. >         2) struct list *friend[numtot];
  32. >
  33. >                                        Fixed:  struct list *friend[totnum]; 
  34. > // NOT numtoto but totnum
  35. >
  36. >                3)       fgets(friend[num]->name[],15,stdin); // Syntax ERROR
  37. >
  38. >                                        Fixed:  fgets(friend[num]->name,15,
  39. >stdin);
  40. >
  41. >Error number 3 occurrs multiple time in your code.
  42. >
  43. >Error number 1 is very common for novice C programmers to make. The 
  44. >totnum macro will be replaced with everything to the right of the 
  45. >white space, (i.e. 20    //total no. of entries in list=20). Look at 
  46. >the source listing to see how tonum is replaced with the macro 
  47. >you've defined.
  48.  
  49. Since we are talking about C code here the only thing to be said is that
  50. // is illegal (it is a syntax error). The only syntax the C language provides
  51. for comments is /* */ . If you set your compiler to an ANSI C conformant mode
  52. it must complain about //, other than within /* */ comments, string literals
  53. (wide character constants?) or part of //* as in:
  54.  
  55.    a = b //**/ 5;
  56.  
  57. Note that is this a legal C statement any C compiler must compile it as
  58.  
  59.    a = b / 5;
  60.  
  61. (launches off-topic)
  62.  
  63. In C++ (as well as C) comments are converted to a white-space character
  64. before macro substitution is performed. So if your C++ compiler compiles:
  65.  
  66. #define totnum 20       //total no. of entries in list=20
  67.  
  68. with different effect to:
  69.  
  70. //total no. of entries in list=20
  71. #define totnum 20 
  72.  
  73. it is severely broken.
  74.  
  75. (splash-down)
  76.  
  77. -- 
  78. -----------------------------------------
  79. Lawrence Kirby | fred@genesis.demon.co.uk
  80. Wilts, England | 70734.126@compuserve.com
  81. -----------------------------------------
  82.